package sort;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CatTest {
    public static void main(String[] args) {
        //按名字升序排序
        Cat cat1=new Cat("花花",2,"英国短毛猫");
        Cat cat2=new Cat("凡凡",3,"中华田园猫");
        Cat cat3=new Cat("毛毛",4,"中华田园猫");
        List<Cat> catList=new ArrayList<Cat>();
        catList.add(cat1);
        catList.add(cat2);
        catList.add(cat3);
        System.out.println("按名字/年龄排序前的数据:");
        for (Cat cat:catList){
            System.out.println(cat);
        }
        System.out.println("*********************************");
        //按名字进行升序排序
        Collections.sort(catList,new NameComparator());
        System.out.println("按名字排序后的数据:");
        for (Cat cat:catList){
            System.out.println(cat);
        }
        System.out.println("*********************************");
        //按年龄进行降序排序
        Collections.sort(catList,new AgeComparator());
        System.out.println("按年龄排序后的数据:");
        for (Cat cat:catList){
            System.out.println(cat);
        }
    }
}
